-
-
Notifications
You must be signed in to change notification settings - Fork 735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple interceptor enable option #2256
base: main
Are you sure you want to change the base?
Conversation
Can you please create an issue to discuss first? We are trying to clean up the current code base and APIs of nock, this will make it more complex. It feels like a patch for a bigger underlying problem. I don't think that it's something we can address right now |
@gr2m I think it is self-evident that there is no simple way to toggle an interceptor. If there is a cleanup of the current code base, it should have a way to toggle an interceptor. |
We can leave the PR open to see if others run into the same problem. |
@gr2m Sure, I'm fine with that 👍 |
let me know if you are interested in this kind of feature soon |
Until it will be merge (if it ever will) - here is a current work around export function nockDisableScope(scope: nock.Scope) {
// @ts-ignore
const interceptors = scope.keyedInterceptors;
// @ts-ignore
scope.interceptors.forEach(nock.removeInterceptor);
return interceptors;
}
export function nockDisableScopes(scopes: nock.Scope[]): [nock.Scope, any[]][] {
const scopesWithListeners: [nock.Scope, any[]][] = [];
for (const scope of scopes) {
scopesWithListeners.push([scope, nockDisableScope(scope)]);
}
return scopesWithListeners;
}
export function nockEnableScope(scope: nock.Scope, interceptors: any[]) {
for (const [key, keyInterceptors] of Object.entries(interceptors)) {
// @ts-ignore
const previousInterceptors = [...keyInterceptors];
for (const currentKeyInterceptor of previousInterceptors) {
// @ts-ignore
scope.add(key, currentKeyInterceptor);
}
}
}
export function nockEnableScopes(scopesWithListeners: [nock.Scope, any[]][]): void {
for (const [scope, scopeEventWithListeners] of scopesWithListeners) {
nockEnableScope(scope, scopeEventWithListeners);
}
}
|
Nice, I... don't use nock atm but ill get to this as well when I need it |
This PR allows a simple
enabled
property to be processedBefore:
.removeInterceptor
and call.get
on the interceptor with the same function call againAfter:
enabled
property to falseWhat this PR covers
Summary of code change:
enabled
inInterceptor
InterceptedRequestRouter#startPlayback
formatchedInterceptor
list